*--------------------------------------------------------------; * Estimates the mean or total from a set of ns repeated ; * systematic samples. ; *--------------------------------------------------------------; %macro est_rsys(sample=,setup=,response=,param=,npop=,fpc=, ns=,rep=); %if %length(&rep) = 0 %then %let rep = %str(rep); %if %length(&sample)= 0 %then %let sample = %str(sample); %if %length(&npop) = 0 %then %let npop = %str(npop); %if %length(&setup) = 0 %then %do; data kp_; %end; %else %do; data kp_; set &setup; %end; proc sort data = &sample; by &rep; proc means data = &sample noprint; by &rep; var &response; output out = temp_ mean = ybars_ n = nrep_; proc means data = temp_ noprint; var ybars_ nrep_; output out = new_ mean = mu_hat_ sum = temp n_ var = var_ n=nsamps_; data new_; set new_; call symput('ns',trim(left(nsamps_))); call symput('n',trim(left(n_))); data est_; merge new_ &setup; %if %length(&fpc) > 0 %then %do; fpc_ = &fpc; var_mu_ = fpc_*var_/&ns; std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; keep mu_hat_ std_mu_ bnd_mu_ ; %end; %else %do; fpc_ = (&npop - &n)/&npop; var_mu_ = fpc_*var_/&ns; std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; tau_hat_ = &npop*mu_hat_; var_tau_ = &npop**2*var_mu_; std_tau_ = &npop*std_mu_; bnd_tau_ = 2*std_tau_; keep mu_hat_ std_mu_ bnd_mu_ tau_hat_ std_tau_ bnd_tau_; %end; %if %index(%upcase(¶m),MEAN) > 0 %then %do; proc print data = est_ noobs split='*'; title1 "Estimate of the Population Mean"; title2 "Repeated Systematic Sampling Design"; title3 "ns = &ns n = &n"; title4 "Response Variable = &response"; label mu_hat_ = 'Estimate'; label std_mu_ = 'Standard*Error'; label bnd_mu_ = 'Bound'; var mu_hat_ std_mu_ bnd_mu_; %end; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_ noobs split='*'; title1 "Estimate of the Population Total"; title2 "Repeated Systematic Sampling Design"; title3 "ns = &ns n = &n"; title4 "Response Variable = &response"; label tau_hat_ = 'Estimate'; label std_tau_ = 'Standard*Error'; label bnd_tau_ = 'Bound'; var tau_hat_ std_tau_ bnd_tau_; %end; run; title; %mend est_rsys;